package com.vtquang.mymaps;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class PanoramioInformation { 
	
	private static final String TAG_PHOTOS = "photos";
	private static final String TAG_HEIGHT = "height";
	private static final String TAG_LATITUDE = "latitude";
	private static final String TAG_LONGTITUDE = "longitude";
	private static final String TAG_OWNER_ID = "owner_id";
	private static final String TAG_OWNER_NAME = "owner_name";
	private static final String TAG_OWNER_URL = "owner_url";
	private static final String TAG_PHOTO_FILE_URL = "photo_file_url";
	private static final String TAG_PHOTO_ID = "photo_id";
	private static final String TAG_PHOTO_TITLE = "photo_title";
	private static final String TAG_PHOTO_URL = "photo_url"; 
	private static final String TAG_UPLOAD_DATE = "upload_date";
	private static final String TAG_WIDTH = "width";
	
	public List<Item> _photos; 
	public PanoramioInformation() {
		this._photos = new ArrayList<Item>();
	}
	
	public PanoramioInformation(List<Item> list){
		this._photos = list;
	}
	
	public PanoramioInformation(JSONObject json){
		this._photos = new ArrayList<Item>();
		JSONArray jphotos = null;
		
		try {
			jphotos = json.getJSONArray(TAG_PHOTOS);
			
			int count = jphotos.length();
			for (int i = 0; i < count; i++) {
				JSONObject p = jphotos.getJSONObject(i);
				Item item = new Item();
				item.height = p.getString(TAG_HEIGHT);
				item.latitude = p.getString(TAG_LATITUDE);
				item.longitude = p.getString(TAG_LONGTITUDE);
				item.owner_id = p.getString(TAG_OWNER_ID);
				item.owner_name = p.getString(TAG_OWNER_NAME);
				item.owner_url = p.getString(TAG_OWNER_URL);
				item.photo_file_url = p.getString(TAG_PHOTO_FILE_URL);
				item.photo_id = p.getString(TAG_PHOTO_ID);
				item.photo_title = p.getString(TAG_PHOTO_TITLE);
				item.photo_url = p.getString(TAG_PHOTO_URL);
				item.upload_dat = p.getString(TAG_UPLOAD_DATE);
				item.width = p.getString(TAG_WIDTH);
				
				_photos.add(item);
			}
			
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace(); 
		}
	}

	public class Item {
		public String upload_dat;
		public String owner_name;
		public String photo_id;
		public String longitude;
		public String height;
		public String width;
		public String photo_title;
		public String latitude;
		public String owner_url;
		public String photo_url;
		public String photo_file_url;
		public String owner_id; 
	}
}